﻿using Commonality;
using ICarlifeRespository;
using ICarlifeService;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CarlifeService
{
    public class BrandService : BaseServer<Brand>, IBrandService
    {
        private readonly IBrandRespository db;
        private readonly IUOfWork uOfWork;
        public BrandService(IBrandRespository db, IUOfWork uOfWork) : base(db, uOfWork)
        {
            this.db = db;
            this.uOfWork = uOfWork;
        }

        public  List<TreeBindDTO> BindTree(int id = 0)
        {
            List<TreeBindDTO> dto = new List<TreeBindDTO>();
            var list = db.GetAll();
            var list1 = list.Where(x => x.Pid == id);
            foreach (var item in list1)
            {
#pragma warning disable CS8601 // 引用类型赋值可能为 null。
                dto.Add(new TreeBindDTO() { Value = item.Id.ToString(), Text = item.BrandName, children = BindTree(item.Id) });
#pragma warning restore CS8601 // 引用类型赋值可能为 null。
            }
#pragma warning disable CS8603 // 可能返回 null 引用。
            return dto.Count() > 0 ? dto : null;
#pragma warning restore CS8603 // 可能返回 null 引用。
        }
    }
}
